package com.demo.scenic.controller;

import com.demo.scenic.common.BaseResponse;
import com.demo.scenic.domain.*;
import com.demo.scenic.domain.vo.ScenicNameVo;
import com.demo.scenic.domain.vo.ScenicVo;
import com.demo.scenic.service.BusinessService;
import com.demo.scenic.shiro.AccountProfile;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.UnknownAccountException;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresAuthentication;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.web.bind.annotation.*;

@Api(tags = "商户以及管理端")
@RestController
@RequestMapping("/business")
@AllArgsConstructor
public class BusinessController {
    private final BusinessService businessService;

    @GetMapping("/getScenicNames")
    @ApiOperation(value = "获取景区名称", notes = "获取景区名称",response = ScenicNameVo.class)
    @RequiresRoles(value = {"MERCHANT", "ADMIN"},logical = Logical.OR)
    public BaseResponse getScenicNames() {
        return businessService.getScenicNames();
    }

    @GetMapping("/getScenicList")
    @ApiOperation(value = "获取景区列表", notes = "获取景区列表",response = ScenicVo.class)
    @RequiresAuthentication
    public BaseResponse getScenicList() throws UnknownAccountException {
        AccountProfile accountProfile;
        try {
            accountProfile = (AccountProfile) SecurityUtils.getSubject().getPrincipals().getPrimaryPrincipal();
        } catch (Exception e) {
            throw new UnknownAccountException("请先登录");
        }
        return businessService.getScenic(accountProfile);
    }

    @GetMapping("/bindScenic/{id}")
    @ApiOperation(value = "绑定景区", notes = "绑定景区")
    @RequiresRoles("MERCHANT")
    public BaseResponse bindScenic(@PathVariable Integer id) {
        AccountProfile accountProfile = (AccountProfile) SecurityUtils.getSubject().getPrincipals().getPrimaryPrincipal();
        return businessService.bindScenic(accountProfile,id);
    }

    @PostMapping("/addScenicBase")
    @RequiresRoles("ADMIN")
    @ApiOperation(value = "添加景区基本信息", notes = "添加景区基本信息")
    public BaseResponse addScenic(@RequestBody ScenicBase scenic) {
        return businessService.addScenicBase(scenic);
    }

    @PostMapping("/updateScenicBase")
    @RequiresRoles(value = {"MERCHANT", "ADMIN"},logical = Logical.OR)
    @ApiOperation(value = "修改景区基本信息", notes = "修改景区基本信息")
    public BaseResponse updateScenic(@RequestBody ScenicBase scenic) {
        return businessService.updateScenicBase(scenic);
    }

    @DeleteMapping("/deleteScenicBase/{id}")
    @RequiresRoles("ADMIN")
    @ApiOperation(value = "根据景区id删除景区基本信息（管理员可删除）", notes = "根据景区id删除景区基本信息（管理员可删除）")
    public BaseResponse deleteScenic(@PathVariable Integer id) {
        return businessService.deleteScenicBase(id);
    }

    @PostMapping("/addScenicPhoto")
    @ApiOperation(value = "添加景区图片", notes = "添加景区图片")
    @RequiresRoles(value = {"MERCHANT", "ADMIN"},logical = Logical.OR)
    public BaseResponse addScenicPhoto(@RequestBody ScenicPhoto scenicPhoto) {
        return businessService.addScenicImage(scenicPhoto);
    }

    @PostMapping("/updateScenicPhoto")
    @ApiOperation(value = "修改景区图片", notes = "修改景区图片")
    @RequiresRoles(value = {"MERCHANT", "ADMIN"},logical = Logical.OR)
    public BaseResponse updateScenicPhoto(@RequestBody ScenicPhoto scenicPhoto) {
        return businessService.updateScenicImage(scenicPhoto);
    }

    @DeleteMapping("/deleteScenicPhoto/{id}")
    @ApiOperation(value = "根据图片id删除景区图片", notes = "根据图片id删除景区图片")
    @RequiresRoles(value = {"MERCHANT", "ADMIN"},logical = Logical.OR)
    public BaseResponse deleteScenicPhoto(@PathVariable Integer id) {
        return businessService.deleteScenicImage(id);
    }

    @PostMapping("/addScenicOther")
    @ApiOperation(value = "添加景区其他信息", notes = "添加景区其他信息")
    @RequiresRoles(value = {"MERCHANT", "ADMIN"},logical = Logical.OR)
    public BaseResponse addScenicOther(@RequestBody ScenicOther scenicOther) {
        return businessService.addScenicOther(scenicOther);
    }

    @PostMapping("/updateScenicOther")
    @ApiOperation(value = "修改景区其他信息", notes = "修改景区其他信息")
    @RequiresRoles(value = {"MERCHANT", "ADMIN"},logical = Logical.OR)
    public BaseResponse updateScenicOther(@RequestBody ScenicOther scenicOther) {
        return businessService.updateScenicOther(scenicOther);
    }

    @DeleteMapping("/deleteScenicOther/{id}")
    @ApiOperation(value = "根据景区id删除景区其他信息", notes = "根据景区id删除景区其他信息")
    @RequiresRoles(value = {"MERCHANT", "ADMIN"},logical = Logical.OR)
    public BaseResponse deleteScenicOther(@PathVariable Integer id) {
        return businessService.deleteScenicOther(id);
    }



    @PostMapping("/addTicket")
    @ApiOperation(value = "添加门票类型", notes = "添加门票类型")
    @RequiresRoles(value = {"MERCHANT", "ADMIN"},logical = Logical.OR)
    public BaseResponse addTicket(@RequestBody TicketType ticketType) {
        return businessService.addTicketType(ticketType);
    }

    @PostMapping("/updateTicket")
    @ApiOperation(value = "修改门票类型", notes = "修改门票类型")
    @RequiresRoles(value = {"MERCHANT", "ADMIN"},logical = Logical.OR)
    public BaseResponse updateTicket(@RequestBody TicketType ticketType) {
        return businessService.updateTicketType(ticketType);
    }

    @GetMapping("/updateTicketStatus/{id}")
    @ApiOperation(value = "修改门票状态", notes = "修改门票状态")
    @RequiresRoles(value = {"MERCHANT", "ADMIN"},logical = Logical.OR)
    public BaseResponse updateTicketStatus(@PathVariable Integer id) {
        return businessService.updateTicketStatus(id);
    }

    @DeleteMapping("/deleteTicket/{id}")
    @ApiOperation(value = "根据门票id删除门票", notes = "根据门票id删除门票")
    @RequiresRoles(value = {"MERCHANT", "ADMIN"},logical = Logical.OR)
    public BaseResponse deleteTicket(@PathVariable Integer id) {
        return businessService.deleteTicketType(id);
    }

    @PostMapping("/addTimeConfig")
    @ApiOperation(value = "设置景区可购票入场时间段", notes = "设置景区可购票入场时间段")
    @RequiresRoles(value = {"MERCHANT", "ADMIN"},logical = Logical.OR)
    public BaseResponse addTimePeriod(@RequestBody TimeConfig timeConfig) {
        return businessService.addTimeConfig(timeConfig);
    }

    @PostMapping("/updateTimeConfig")
    @ApiOperation(value = "修改景区可购票入场时间段", notes = "修改景区可购票入场时间段")
    @RequiresRoles(value = {"MERCHANT", "ADMIN"},logical = Logical.OR)
    public BaseResponse updateTimePeriod(@RequestBody TimeConfig timeConfig) {
        return businessService.updateTimeConfig(timeConfig);
    }

    @PostMapping("/addActivity")
    @ApiOperation(value = "添加景区活动", notes = "添加景区活动")
    @RequiresRoles(value = {"MERCHANT", "ADMIN"},logical = Logical.OR)
    public BaseResponse addActivity(@RequestBody ScenicActivity activity) {
        return businessService.addScenicActivity(activity);
    }
    @PostMapping("/updateActivity")
    @ApiOperation(value = "修改景区活动", notes = "修改景区活动")
    @RequiresRoles(value = {"MERCHANT", "ADMIN"},logical = Logical.OR)
    public BaseResponse updateActivity(@RequestBody ScenicActivity activity) {
        return businessService.updateScenicActivity(activity);
    }
    @DeleteMapping("/deleteActivity/{id}")
    @ApiOperation(value = "根据活动id删除活动", notes = "根据活动id删除活动")
    @RequiresRoles(value = {"MERCHANT", "ADMIN"},logical = Logical.OR)
    public BaseResponse deleteActivity(@PathVariable Integer id) {
        return businessService.deleteScenicActivity(id);
    }
    @GetMapping("/updateActivityStatus/{id}")
    @ApiOperation(value = "修改活动状态", notes = "修改活动状态")
    @RequiresRoles(value = {"MERCHANT", "ADMIN"},logical = Logical.OR)
    public BaseResponse updateActivityStatus(@PathVariable Integer id) {
        return businessService.updateScenicActivityStatus(id);
    }

    // 根据景区ID获取景区其他信息
    @GetMapping("/getScenicOther/{id}")
    @ApiOperation(value = "根据景区ID获取景区其他信息", notes = "根据景区ID获取景区其他信息")
    @RequiresRoles(value = {"MERCHANT", "ADMIN"},logical = Logical.OR)
    public BaseResponse getScenicOther(@PathVariable Integer id) {
        return BaseResponse.ok(businessService.getScenicOther(id));
    }

    // 根据景区ID获取景区图片
    @GetMapping("/getScenicImg/{id}")
    @ApiOperation(value = "根据景区ID获取景区图片", notes = "根据景区ID获取景区图片")
    @RequiresRoles(value = {"MERCHANT", "ADMIN"},logical = Logical.OR)
    public BaseResponse getScenicImg(@PathVariable Integer id) {
        return BaseResponse.ok(businessService.getScenicImage(id));
    }

    //根据景区id获取景区票务信息
    @GetMapping("/getTicket/{id}")
    @ApiOperation(value = "根据景区id获取景区票务信息", notes = "根据景区id获取景区票务信息")
    @RequiresRoles(value = {"MERCHANT", "ADMIN"},logical = Logical.OR)
    public BaseResponse getTicket(@PathVariable Integer id) {
        return BaseResponse.ok(businessService.getTicketType(id));
    }

    // 根据景区id获取可预约时间段信息
    @GetMapping("/getTimeConfig/{id}")
    @ApiOperation(value = "根据景区id获取可预约时间段配置信息", notes = "根据景区id获取可预约时间段配置信息")
    @RequiresRoles(value = {"MERCHANT", "ADMIN"},logical = Logical.OR)
    public BaseResponse getTimeConfig(@PathVariable Integer id) {
        return BaseResponse.ok(businessService.getScenicTime(id));
    }

    // 根据景区id获取景区活动信息
    @GetMapping("/getActivity/{id}")
    @ApiOperation(value = "根据景区id获取景区活动信息", notes = "根据景区id获取景区活动信息")
    @RequiresRoles(value = {"MERCHANT", "ADMIN"},logical = Logical.OR)
    public BaseResponse getActivity(@PathVariable Integer id) {
        return BaseResponse.ok(businessService.getScenicActivity(id));
    }
    // 根据景区id获取可购票时间段信息
    @GetMapping("/getTicketTime/{id}")
    @ApiOperation(value = "根据景区id获取可购票时间段信息", notes = "根据景区id获取可购票时间段信息")
    @RequiresRoles(value = {"MERCHANT", "ADMIN"},logical = Logical.OR)
    public BaseResponse getTicketTime(@PathVariable Integer id) {
        return BaseResponse.ok(businessService.getTimePeriod(id));
    }

    @GetMapping("/getScenicBookRecord/{id}")
    @ApiOperation(value = "根据景区id获取景区预约记录", notes = "根据景区id获取景区预约记录")
    @RequiresRoles(value = {"MERCHANT", "ADMIN"},logical = Logical.OR)
    public BaseResponse getScenicBookRecord(@PathVariable Integer id) {
        return businessService.getScenicOrder(id);
    }

    // 新增景区介绍图片
    @PostMapping("/addScenicImg")
    @ApiOperation(value = "新增景区介绍图片", notes = "新增景区介绍图片")
    @RequiresRoles(value = {"MERCHANT", "ADMIN"},logical = Logical.OR)
    public BaseResponse addScenicImg(@RequestBody ScenicImg scenicImg) {
        return businessService.addScenicImg(scenicImg);
    }

    // 更新景区介绍图片
    @PostMapping("/updateScenicImg")
    @ApiOperation(value = "更新景区介绍图片", notes = "更新景区介绍图片")
    @RequiresRoles(value = {"MERCHANT", "ADMIN"},logical = Logical.OR)
    public BaseResponse updateScenicImg(@RequestBody ScenicImg scenicImg) {
        return businessService.updateScenicImg(scenicImg);
    }
    // 删除景区介绍图片
    @DeleteMapping("/deleteScenicImg/{id}")
    @ApiOperation(value = "删除景区介绍图片", notes = "删除景区介绍图片")
    @RequiresRoles(value = {"MERCHANT", "ADMIN"},logical = Logical.OR)
    public BaseResponse deleteScenicImg(@PathVariable Integer id) {
        return businessService.deleteScenicImg(id);
    }
    // 根据id获取景区介绍图片
    @GetMapping("/getScenicImgById/{id}")
    @ApiOperation(value = "根据id获取景区介绍图片", notes = "根据id获取景区介绍图片")
    @RequiresRoles(value = {"MERCHANT", "ADMIN"},logical = Logical.OR)
    public BaseResponse getScenicImgById(@PathVariable Integer id) {
        return BaseResponse.ok(businessService.getScenicImg(id));
    }
}
